﻿using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Business;
using System.Data;
using University.Workshop.Model;

namespace University.Workshop.Tests
{
    [TestClass()]
    public class UserManagerDataAccessTest
    {


        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod()]
        public void InsertUserTest()
        {
            Random ran = new Random();
            int num = ran.Next(10000);
            User user = new User()
            {
                Id=num.ToString(),
                Name="Juan",
                Surname1="Uribe",
                Surname2="Salvarierra",
                Telephone="4291861",
                CellPhone="70965566",
                Address="calle prueba",
                Password="123",
                Occupation="Administracion"
            }; 
            bool resp=UserManagerDataAccess.InsertUser(user);
            Assert.IsTrue(resp);
        }

        [TestMethod()]
        public void CheckIfExistsSameIdDataAccessTest()
        {
            string id = "1";
            bool expected = false;
            bool actual;
            actual = UserManagerDataAccess.CheckIfExistsSameId(id);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void CheckIfPasswordIsCorrectTest()
        {
            string password = "123";
            string id = "1";
            bool expected = true;
            bool actual;
            actual = UserManagerDataAccess.CheckIfPasswordIsCorrect(password, id);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void CheckIfPasswordIsCorrectTestFail()
        {
            string password = "mauri";
            string id = "1";
            bool expected = false;
            bool actual;
            actual = UserManagerDataAccess.CheckIfPasswordIsCorrect(password, id);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void UpdatePasswordTest()
        {
            string id = "1";
            string password = "123";
            bool expected = true; 
            bool actual;
            actual = UserManagerDataAccess.UpdatePassword(id, password);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void UpdateUserDataTest()
        {
            User user = new User()
            {
                Id = "1",
                Name = "Javier",
                Surname1 = "Pardo",
                Surname2 = "Gomez",
                Telephone = "",
                CellPhone = "",
                Address = "micasa",
                Occupation = "Administracion"
            }; 
            bool expected = true;
            bool actual;
            actual = UserManagerDataAccess.UpdateUserData(user);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SearchAUser
        ///</summary>
        [TestMethod()]
        public void SearchAUserTest()
        {
            string id = "%" + "1" + "%";
            string name = "%" + string.Empty + "%";
            string surname1 = "%" + string.Empty + "%";
            string surname2 = "%" + string.Empty + "%"; 
            DataTable actual;
            actual = UserManagerDataAccess.SearchAUser(id, name, surname1, surname2);
            Assert.AreNotEqual(0, actual.Rows.Count);
        }
    }
}
